<!-- templates/login.html -->
<!-- templates/login.html -->

{% extends 'base.html' %}

{% block content %}
{% if form.non_field_errors %}
    <div class="alert alert-danger mb-3">
        {{ form.non_field_errors|join:"<br>" }}
    </div>
{% endif %}
<div class="row justify-content-center">
    <div class="col-md-6">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h3 class="mb-0">用户登录</h3>
            </div>
            <div class="card-body">
                <form method="post" action="{% url 'login' %}">

                    {% csrf_token %}

                    <div class="mb-3">
                        <label for="{{ form.username.id_for_label }}" class="form-label">用户名</label>
                        <input type="text" class="form-control {% if form.username.errors %}is-invalid{% endif %}"
                               id="{{ form.username.id_for_label }}" name="{{ form.username.name }}"
                               value="{{ form.username.value|default:'' }}" required>
                        {% if form.username.errors %}
                            <div class="invalid-feedback">
                                {{ form.username.errors|join:", " }}
                            </div>
                        {% endif %}
                    </div>

                    <div class="mb-4">
                        <label for="{{ form.password.id_for_label }}" class="form-label">密码</label>
                        <input type="password" class="form-control {% if form.password.errors %}is-invalid{% endif %}"
                               id="{{ form.password.id_for_label }}" name="{{ form.password.name }}" required>
                        {% if form.password.errors %}
                            <div class="invalid-feedback">
                                {{ form.password.errors|join:", " }}
                            </div>
                        {% endif %}
                    </div>

                    <button type="submit" class="btn btn-primary w-100">登录</button>
                </form>

                <div class="mt-4 text-center">
                    还没有账户? <a href="{% url 'register' %}" class="text-primary">立即注册</a>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}